package com.springcloud.client.modules.rocketmq;

import java.math.BigDecimal;

import javax.annotation.Resource;

import org.apache.rocketmq.spring.starter.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.springcloud.entity.OrderPaidEvent;

@RestController
public class ProducerController {
	
	@Resource
	private  RocketMQTemplate rocketMQTemplate;
	

	@RequestMapping("send")
	public void send() {
		/**
		 * 走 RocketMQTemplat类中的doConvert方法
		 */
		// 发送字符串
		rocketMQTemplate.convertAndSend("string-topic", "一笔订单队列");

		// 发送用户定义的对象
		rocketMQTemplate.convertAndSend("order-paid-topic", new OrderPaidEvent("坚果大礼包", new BigDecimal("88.00")));

		// 用特殊标签发送消息
		rocketMQTemplate.convertAndSend("message-ext-topic:tag0", "I'm from tag0"); //not be consume
		rocketMQTemplate.convertAndSend("message-ext-topic:tag1", "薯片");
		
		/**
		 * 不走 RocketMQTemplat类中的doConvert方法
		 */
		// 用Spring-messageing消息包发送字符串
		rocketMQTemplate.send("string-topic", MessageBuilder.withPayload("一箱啤酒").build());
		
		
	}
	
}
